<template>
  <el-dialog :title="title" :visible.sync="open" :width="dialogWidth" destroy-on-close append-to-body>
    <el-form :model="formData" size="small" label-width="120px" ref="form">
      <el-row>
        <el-col :span="12">
          <el-form-item label="执行方式" prop="cate">
            <span v-if="formData.executeType == 1">执行预案</span>
            <span v-if="formData.executeType == 2">指派任务</span>
            <span v-if="formData.executeType == 4">立即执行</span>
            <span v-if="formData.executeType == 3">终止任务</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="任务内容" prop="cate">
            {{ formData.taskContent }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="formData.taskAttaches.length > 0">
        <el-col :span="12">
          <el-form-item label="任务附件" prop="cate">
            <uploader :files="formData.taskAttaches" :canUpload="false" @onDownload="handleTaskAttachDownload"
              width="80px" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="指派时间" prop="cate">
            {{ formData.startTime }}
          </el-form-item>
        </el-col>
      </el-row>
      <template v-if="formData.executeType == 1">
        <el-row :gutter="15">
          <el-col :span="24">
            <el-form-item label="预案" prop="event_name">
              {{ planTitle }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="响应级别" prop="event_name">
              {{ formData.planType }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="24">
            <el-form-item label="执行人" prop="dept">
              {{ nickName }}
            </el-form-item>
          </el-col>
        </el-row>
      </template>
      <template v-if="formData.executeType == 4">
        <el-row>
          <el-col :span="24">
            <el-form-item label="任务反馈">
              <span>{{ formData.submitContent }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="反馈时间">
              {{ formData.submitTime }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="反馈附件" prop="countText">
              <el-table :data="uploadinglist" max-height="250">
                <el-table-column prop="attachname" label="名称" align="center">
                </el-table-column>
                <el-table-column prop="attachsize" label="大小" align="center">
                </el-table-column>
                <el-table-column prop="attachtype" label="类型" align="center">
                </el-table-column>
                <el-table-column label="操作" align="center">
                  <template slot-scope="scope">
                    <el-button type="text" size="small" @click="downloadFile(scope.row)">
                      下载
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-form-item>
          </el-col>
        </el-row>
      </template>
      <template v-if="formData.executeType == 2">
        <el-row>
          <el-col :span="24">
            <el-form-item label="指派任务" prop="countText">
              <el-table :data="formData.hdTasks" size="mini" border :style="{ width: '100%', marginTop: '15px' }">
                <el-table-column type="expand">
                  <template slot-scope="scope">
                    <div class="task-report">
                      <el-form label-position="left" class="demo-table-expand" label-width="100px">
                        <template v-if="scope.row.status == 2">
                          <el-row>
                            <el-col :span="24">
                              <el-form-item label="任务反馈">
                                <span>{{ scope.row.submitContent }}</span>
                              </el-form-item>
                            </el-col>
                          </el-row>
                          <el-row>
                            <el-col :span="12">
                              <el-form-item label="反馈文件">
                                <el-button type="text" @click="handleTaskReportAttach(scope.row)">查看任务反馈文件>></el-button>
                              </el-form-item>
                            </el-col>
                            <el-col :span="12">
                              <el-form-item label="反馈时间">
                                {{ scope.row.submitTime }}
                              </el-form-item>
                            </el-col>
                          </el-row>
                        </template>
                        <template v-else>
                          <el-row>
                            <el-col :span="24">
                              <el-form-item label="任务反馈">
                                <span>任务未完成</span>
                              </el-form-item>
                            </el-col>
                          </el-row>
                        </template>
                      </el-form>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column prop="userName" label="执行人" width="180">
                </el-table-column>
                <el-table-column prop="deptName" label="所属部门" width="180">
                </el-table-column>
                <!-- <el-table-column prop="groupName" label="所属分组" width="180" v-if="handleInfo.type == 1">
                </el-table-column> -->
                <el-table-column prop="taskContent" label="任务内容"> </el-table-column>
              </el-table>
            </el-form-item>
          </el-col>
        </el-row>
      </template>
      <template v-if="formData.executeType == 3">
        <el-row>
          <el-col :span="24">
            <el-form-item label="终止原因">
              <span>{{ formData.submitContent }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="终止时间">
              {{ formData.submitTime }}
            </el-form-item>
          </el-col>
        </el-row>
      </template>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="close">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import dialogMixin from "../../../mixins/dialogMixin";
import * as HandleApi from "@/api/response/handle.js";
import Uploader from '@/views/components/uploader/index.vue';

export default {
  name: 'TaskDetailDialog',
  mixins: [dialogMixin],
  components: { Uploader },
  props: {
    handClick: {
      type: Function,
    },
  },
  data() {
    return {
      title: "任务详情",
      open: false,
      formData: {
        taskAttaches: []
      },
      uploadinglist: [],
      countText: "",
      status: 2,
      disabled: false,
      hidden: false,
      //预案任务提交
      type: 2,
      //详情
      flag: "",
      meettype: "",
      executeType: 3,
      responseLevelOption: [
        {
          label: "Ⅰ级响应",
          value: 1,
        },
        {
          label: "Ⅱ级响应",
          value: 2,
        },
        {
          label: "Ⅲ级响应",
          value: 3,
        },
        {
          label: "Ⅳ级响应",
          value: 4,
        },
      ],
      planTitle: '',
      planId: '',
      nickName: ''
    };
  },
  computed: {
    dialogWidth() {
      if (this.executeType == 1) {
        return '600px';
      }
      if (this.executeType == 2) {
        return '80%';
      }
      return '60%'
    }
  },
  methods: {
    //完成任务调
    showDialog(taskId) {
      HandleApi.getTaskInfo(taskId).then(res => {
        console.log(res);
        this.formData = res.data;
      })
      this.open = true;
    },
    handleTaskAttachDownload(row) {
      // 下载附件
      this.download(
        `com/ComAttach/download/${row.attachid}`,
        {},
        `${row.attachname}.${row.attachtype}`
      );
    }
  },
};
</script>

<style lang="scss" scoped>
.task-report {
  padding: 0 20px 20px;
}
</style>
